use tracing_subscriber::fmt;
use tracing_subscriber::layer::SubscriberExt;

/// 初始化日志
pub fn initial() -> anyhow::Result<()> {
    let file_appender = tracing_appender::rolling::daily("./logs", "acmt-server.log");
    let subscriber = tracing_subscriber::registry()
        .with(fmt::Layer::new().with_writer(std::io::stdout)
            .with_ansi(true)
            .with_line_number(true)
            .with_thread_ids(true)
            .with_thread_names(true)
            .with_target(false))
        .with(fmt::Layer::new().with_writer(file_appender).with_ansi(false))
        .with(tracing_subscriber::filter::LevelFilter::TRACE);

    tracing::subscriber::set_global_default(subscriber)?;
    Ok(())
}